package com.hp.bon.sgw.wkflow.impl;

import com.hp.bon.sgw.wkflow.FlowVarObj;

/**
 * 实现固定长度的字符串的函数
 * 
 * @author wuzhih
 * 
 */
public class FixLengthStrFuncVarObj extends FlowVarObj {

	@Override
	public Object getProperty(String express) {
		// 前面部分是 需要操作的字符串，后面部分是需要填充的长度，最后是填充的字符，中间用分号分开
		String[] items = express.split(";");
		String originVal = items[0];
		int targetLen = Integer.parseInt(items[1]);
		char padchar = items[2].charAt(0);
		StringBuilder result = new StringBuilder(targetLen);
		result.append(originVal);
		int len = targetLen - result.length();
		for (int i = 0; i < len; i++) {
			result.insert(0, padchar);
		}
		return result.toString();

	}
	
	public static void main(String[] args)
	{
		String code="02;5;0";
		System.out.println("result:"+ new FixLengthStrFuncVarObj().getProperty(code));
		
	}

}
